﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FirstFloor.P2P.Reversi
{
    public partial class Page : UserControl
    {
        private ReversiGame reversi;

        public Page()
        {
            InitializeComponent();

            if (P2PApplication.Current.P2PNetworkAvailable) {
                this.reversi = new ReversiGame(this.board);
                this.reversi.InfoMessage += reversi_InfoMessage;

                this.btnHints.IsEnabled = true;
                this.btnRestart.IsEnabled = true;
            }
            else {
                SetInfoMessage("Error: P2P network is not available");
            }
        }

        private void SetInfoMessage(string message, params object[] o)
        {
            this.infoMessage.Text = string.Format(message, o);
        }

        private void reversi_InfoMessage(object sender, InfoMessageEventArgs e)
        {
            SetInfoMessage(e.Message);
        }

        private void btnHints_Click(object sender, RoutedEventArgs e)
        {
            this.reversi.HintsEnabled = !this.reversi.HintsEnabled;
            this.btnHints.Content = string.Format("Hints {0}", this.reversi.HintsEnabled ? "ON" : "OFF");
        }

        private void btnRestart_Click(object sender, RoutedEventArgs e)
        {
            this.reversi.Restart();
        }
    }
}
